package com.xybian.controller;

import com.xybian.common.CommonResult;
import com.xybian.entity.SysUser;
import com.xybian.services.LoginService;
import org.apache.tomcat.websocket.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 *
 * @author SongRenShuo
 * @date 2023-12-23
 */
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     *
     * @param user 用户
     * @return 通用返回对象
     * @throws AuthenticationException 身份验证异常
     */
    @PostMapping("/user/login")
    public CommonResult login(@RequestBody SysUser user) throws AuthenticationException {

        return loginService.login(user);
    }

    /**
     * 注销
     *
     * @return 通用返回对象
     */
    @GetMapping("/user/logout")
    public CommonResult logout(){

        return loginService.logout();
    }
}
